<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/white/common/common.jsp"%>
<%@include file="/white/common/taglibs.jsp"%>
<%@page import="java.util.List"%>
<%@page import="java.util.*"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page
	import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@ page import="java.util.ArrayList"%>

<%@page import="com.yellowpage.white.ui.*"%>
<%@page import="com.yellowpage.white.ui.MenuItem"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
	<head>
	<link rel="StyleSheet" href="${ctx}/white/common/dtree.css"
	type="text/css" />
<script type="text/javascript" src="${ctx}/white/common/dtree.js">
</script>
		<script type="text/javascript">      
 function tosearch(){
            var searchForm=document.getElementById("searchForm");
            searchForm.action='manageRegionAction!querySelByPageTree.action';
            searchForm.submit();            
            }
         function displayResult(){
            var result = "<s:property value='result'/>";
            if(result != null && result != ""){
                alert(result);
            }
        } 
function validateModify(){        	
        	var check = document.getElementsByName("selectedIds");
        	var a = 0;
            var id;
            
           
            for(var i=0;i <check.length;i++){
                if(check[i].checked==true){
                    a++;
                    id = check[i].value;
                }
            }
            
            if(a == 1){            	
				var fields = id.split(",");
				var values = new Array(fields.length);

				for(j = 0; j < fields.length; j++) {
					values[j] = fields[j];
				}			
				var code=values[0];	
				code1=code.substring(0,2);
				code2=code.substring(2,4);
				code3=code.substring(4,6);
				code4=code.substring(0,4);
				
				if(code2==00&&code3==00){
				window.top.opener.document.forms[0].regionCode.value =code ;   
				window.top.opener.document.forms[0].cityCode.value =code ;	
				window.top.opener.document.forms[0].destrictCode.value =code ;
				//显示名称
				getCityNameByCode(code);
				getDistNameByCode(code);
				
				}else if(code2!=00&&code3==00){
				window.top.opener.document.forms[0].regionCode.value =code1+"0000" ;   
				window.top.opener.document.forms[0].cityCode.value =code ;	
				window.top.opener.document.forms[0].destrictCode.value =code ;
				//显示名称
				getCityNameByCode(code);
				getDistNameByCode(code);
				
				}else if(code2!=00&&code3!=00){
				window.top.opener.document.forms[0].regionCode.value =code1+"0000" ;   
				window.top.opener.document.forms[0].cityCode.value =code4+"00" ;	
				window.top.opener.document.forms[0].destrictCode.value =code ;
				//显示名称
				getCityNameByCode(code4+"00");
				getDistNameByCode(code);
				}

				
            }else{
                alert("请先选择一条记录!!");
                return false;
            }
        }      
         //根据citycode查询名称
        function  getCityNameByCode(code){
        	var content_Type = "application/x-www-form-urlencoded;charset=UTF-8";
			jQuery.ajax({
			url : 'manageRegionAction!getNameByCode.action',
			type : "POST",
			contentType : content_Type,
			dataType : "text",
			data:{'query_code':code},
			error : function(textStatus, errorThrown) {
			},
			success : function(html) {
				window.top.opener.document.forms[0].cityName.value = html;
			}
		});
		
	} 
        
        //根据distcode查询名称
        function  getDistNameByCode(code){
        	var content_Type = "application/x-www-form-urlencoded;charset=UTF-8";
			jQuery.ajax({
			url : 'manageRegionAction!getNameByCode.action',
			type : "POST",
			contentType : content_Type,
			dataType : "text",
			data:{'query_code':code},
			error : function(textStatus, errorThrown) {
			},
			success : function(html) {
				window.top.opener.document.forms[0].destrictName.value = html;
				window.top.close();
			}
		});

		
	}    
        
		</script>
	</head>
	<body onload="displayResult()">
		<s:form method="post" action="manageRegionAction!querySelByPageTree.action"
			theme="simple" id="searchForm">
			<div id="div_title">
				<h3>
					地区代码选择
				</h3>
				<div id="div_search">
					<table>
						<tr>
							<!-- 查询条件 -->
							<td width="80" align="right">
								地区代码:
							</td>
							<td>
								<s:textfield name="query_regionCode" />
							</td>
							
							<td width="80" align="right">
								<input type="button"
						class="submit_search" value="搜索" id="search" onClick="tosearch();">
							</td>
						</tr>
					</table>
				</div>
			</div>
	
			<div id="div_button">
					<input type="button" value="选择" onclick="return validateModify()"class="input_button">
					<input type="button" value="关闭" onclick="javascript:window.top.close();" class="input_button">
				
			</div>
<div class="dtree" id="dtree" style=" padding-left: 30px;">
		

			<script type="text/javascript">
		d = new dTree('d');		
		d.add(0,-1,'地区代码');
		${manageRegionStr}
  		document.write(d);	
	</script>
		</div>


		</s:form>
	</body>
</html>
